package com.yu.crm.controller;


import com.yu.crm.domain.dto.CrmRoleMenuReq;
import com.yu.crm.domain.pojo.CrmMenu;
import com.yu.crm.service.CrmRoleMenuLinkService;
import com.yxzz.common.helper.valid.ValidatorHelpers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 角色菜单权限表 前端控制器
 * </p>
 *
 * @author donnie-bin
 * @since 2019-06-10
 */

@Api(tags = "角色菜单配置")
@RestController
@RequestMapping("/crm-role-menu-link")
public class CrmRoleMenuLinkController {

    @Autowired
    CrmRoleMenuLinkService roleMenuLinkService;

    @ApiOperation(value = "根据角色ID获取菜单列表")
    @GetMapping(value = "/get-role-menus/{roleId}")
    public List<CrmMenu> getMenusByRoleId(@PathVariable Long roleId){
        ValidatorHelpers.notEmpty(roleId, "角色ID不能为空");
        return roleMenuLinkService.getMenusByRoleId(roleId);
    }

    @ApiOperation(value = "批量更新")
    @PostMapping(value = "/update-batch")
    public void updateBatch(@RequestBody CrmRoleMenuReq roleMenuReq){
        roleMenuLinkService.updateBatch(roleMenuReq);
    }


}